package com.swanclouds.redfish.systems;

import com.google.common.collect.Lists;
import com.swanclouds.api.Apis;
import com.swanclouds.api.systems.LogEntriesService;
import com.swanclouds.api.systems.LogServices;
import com.swanclouds.core.transport.ClientConstants;
import com.swanclouds.model.common.ActionResponse;
import com.swanclouds.model.common.redfish.CollectionResource;
import com.swanclouds.model.systems.LogResource;
import com.swanclouds.redfish.common.redfish.CollectionResourceModel;
import com.swanclouds.redfish.internal.BaseSystemService;
import com.swanclouds.redfish.systems.domain.LogResourceModel;

import java.util.List;

/**
 * @author 张立强
 * @version jdk1.8.0
 */
public class LogServicesImpl extends BaseSystemService implements LogServices {
    /**
     * 查询日志服务集合资源信息
     *
     * @return the LogService Collection info
     */
    @Override
    public CollectionResource get() {
        return get(CollectionResourceModel.class, uri(ClientConstants.SYSTEMS_LOGSERVICE, getSystemId())).execute();
    }

    /**
     * 查询指定日志服务资源信息
     *
     * @param id the log id
     * @return the LogService Resource
     */
    @Override
    public LogResource getLogService(String id) {
        return get(LogResourceModel.class, uri(ClientConstants.SYSTEMS_LOGSERVICE_ID, getSystemId(), id)).execute();
    }

    /**
     * 查询指定日志服务资源列表
     *
     * @return the List LogService Resource
     */
    @Override
    public List<LogResource> list() {
        List<LogResource> logResourceList = Lists.newArrayList();
        CollectionResource resource = get();
        resource.getCollectionResourceList().forEach(ref -> {
            logResourceList.add(get(LogResourceModel.class, uri(ref)).execute());
        });
        return logResourceList;
    }

    /**
     * @param id the Log Id
     * @return 清空日志信息
     */
    @Override
    public ActionResponse clearLog(String id) {
        return postWithResponse(uri(ClientConstants.SYSTEMS_LOGSERVICE_ID_CLEAR, getSystemId(), id)).execute();
    }

    /**
     * @return 查询日志集合资源服务
     */
    @Override
    public LogEntriesService Entries() {
        return Apis.get(LogEntriesService.class);
    }


}
